<?php
	class Fund extends MY_Controller{
		
		public function __construct(){
			parent::__construct();
			$this->load->model('fund_model');
			$this->load->model('kiosk_model');
		}
		
		public function index($limit=FALSE){
			// load the for helper
			$this->load->helper("form");
			
			//set the limit or offset for each page
			$this->fund_model->pager($limit);
			
			// define the link for pagination
			$my_link = site_url('fund');
			
			$data['fund'] = $this->fund_model->getFundList(FALSE, FALSE);
			
			// call the pagination from parent controller
			$this->pager($my_link, $this->fund_model->get_total(), $this->fund_model->get_record_per_page());
					
			$data['title'] = "Fund";
			$data['kiosk'] = $this->kiosk_model->get_kiosk_list();
			$this->load->view('templates/header1', $data);
			$this->load->view('fund/index', $data);
			$this->load->view('templates/right', $data);
			$this->load->view('templates/footer');			
		}
		
		public function filter($kid=FALSE, $limit=FALSE){
			// load the for helper
			$this->load->helper("form");
			
			//set the limit or offset for each page
			$this->fund_model->pager($limit);
			
			// define the link for pagination
			$my_link = site_url('fund/filter/'.$kid);
			
			if($kid!=FALSE){
				$data['fund'] = $this->fund_model->getFundList(FALSE, $kid);
				$data['kid'] = $kid;
				
				$this->pager($my_link, $this->fund_model->get_total($kid), $this->fund_model->get_record_per_page(),4);
				
				// total amount
				$total = $this->fund_model->total_donate($kid);
				$data['total_donate'] = $total['total_donate'];
			}
			$data['title'] = "Fund";
			$data['kiosk'] = $this->kiosk_model->get_kiosk_list();
			$this->load->view('templates/header1', $data);
			$this->load->view('fund/index', $data);
			$this->load->view('templates/right', $data);
			$this->load->view('templates/footer');
		}		
		
		public function displayForm($id=FALSE){			
				$this->load->helper("form");
				$data = array();
				if($id!=FALSE){
					$data['fund'] = $this->fund_model->getFundList($id);				
				}
				$data['title']="Fund";
				$data['kiosk'] = $this->kiosk_model->get_kiosk_list();
				$this->load->view('templates/header1', $data);
				$this->load->view('fund/form', $data);
				$this->load->view('templates/right', $data);
				$this->load->view('templates/footer');
			
		}
		
		public function create(){
			$this->displayForm();
		}
		
		public function edit($id){
			$this->displayForm($id);
		}
		
		public function delete($id){
			$this->fund_model->delete($id);
			redirect("fund", "refresh");
		}
		
		public function save(){			
				$this->load->helper("form");
				$this->load->library('form_validation');
				$this->form_validation->set_rules('donate', 'Donate', 'required');
				if ($this->form_validation->run() === FALSE){
					$data['title']="Fund";
					$data['kiosk'] = $this->kiosk_model->get_kiosk_list();
					$this->load->view('templates/header1', $data);
					$this->load->view('fund/form', $data);
					$this->load->view('templates/right', $data);
					$this->load->view('templates/footer');
				}
				else{
					$this->fund_model->save();
					redirect("fund", "refresh");
				}			
		}
		
	}
?>